import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.JEditorPane;
import javax.swing.BoxLayout;
import java.awt.FlowLayout;

import javax.swing.JOptionPane;
import javax.swing.JSplitPane;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JPasswordField;
import java.util.*;


public class Login {

	private JFrame frame;
	private JTextField textField;
	private final Action action = new SwingAction();
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login window = new Login();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Login() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 495, 215);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 11, 458, 109);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setBounds(52, 60, 80, 14);
		panel.add(lblPassword);
		lblPassword.setFont(new Font("Times New Roman", Font.BOLD, 17));
		
		textField = new JTextField();
		textField.setBounds(142, 24, 256, 24);
		panel.add(textField);
		textField.setColumns(10);
		
		JLabel lblUsername = new JLabel("Username:");
		lblUsername.setBounds(52, 24, 80, 25);
		panel.add(lblUsername);
		lblUsername.setFont(new Font("Times New Roman", Font.BOLD, 17));
		
		passwordField = new JPasswordField();
		passwordField.setBounds(142, 59, 256, 24);
		panel.add(passwordField);
		
		JButton btnLogin = new JButton("Login");
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String value1=textField.getText();
				String value2=new String(passwordField.getPassword());
				Connection con = null;
				String url="jdbc:oracle:thin:@localhost:1521:XE";
				String driver="oracle.jdbc.driver.OracleDriver";
				String user="bitu";
				String pass="bitu";
				try{
					Class.forName(driver);
					con=DriverManager.getConnection(url,user,pass);
					Statement st=con.createStatement();
					String sql="select * from login where username='"+value1+"' and password='"+value2+"' ";
					ResultSet rs=st.executeQuery(sql);
					
					if(rs.next())
					{
						JOptionPane.showMessageDialog(null,"Login Successful! ","Success",JOptionPane.PLAIN_MESSAGE);
					}
					else
	                {
	                    JOptionPane.showMessageDialog(null,"Login Unsuccessful!","Error",1);
	                }
					
				}
				catch(Exception e){
					e.printStackTrace();
				}
				
			}
		});
		btnLogin.setFont(new Font("Tahoma", Font.BOLD, 12));
		btnLogin.setBounds(187, 131, 89, 23);
		frame.getContentPane().add(btnLogin);
	}
	private class SwingAction extends AbstractAction {
		public SwingAction() {
			putValue(NAME, "SwingAction");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}
		public void actionPerformed(ActionEvent e) {
		}
	}
}
